<!DOCTYPE html>
<html class="ui-page-login">

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../css/mui.min.css">
	</head>

	<body>
		<header class="mui-bar mui-bar-nav" style="height: 55px;">
			<div style="margin-top: 15px;">
				<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
				<h1 class="mui-title">已完成</h1>
			</div>
		</header>
		<div class="mui-content">
			<div id="count_down" style="width: 100%;">
				<ul class="mui-content" id="show" style="margin-left: -10%;">
				</ul>
			</div>
		</div>
	</body>
	<script src="../js/mui.min.js"></script>
	<script src="../js/jquery-1.6.2.min.js"></script>
	<script src="../js/urlconfiguration.js"></script>
	<script>
		var flag = 1;
		var jobitem_user_id = [];
		var user_id = localStorage.getItem("user_id");
		var appraiseobject_id = [];
		var jobtype_id = [];
		//当子页面返回时，刷新本页面；
		window.addEventListener('refresh', function(e) {
			location.reload();
		});
		//自执行函数
		(function($, doc) {
			$.init();
			$.plusReady(function() {
				var w = plus.nativeUI.showWaiting("正在加载...\n");
				jQuery.ajax({
					contentType: "application/json",
					type: "GET",
					url: url_3 + "show_jobitem_users_his.do?jsoncallback=?",
					data: "user_id=" + user_id,
					dataType: "json",
					success: function(data) {
						if(data.msg != null) {
							if(data.msg.length == 0) {
								mui.alert("暂无订单信息");
							}
							for(i = 0; i < data.msg.length; i++) {
								var button;
								appraiseobject_id[i] = data.msg[i].jobitem_user.jobitem.job.user.id;
								console.log("boss_id" + data.msg[i].jobitem_user.jobitem.job.user.id);
								jobitem_user_id[i] = data.msg[i].jobitem_user.id;
								jobtype_id[i] = data.msg[i].jobitem_user.jobitem.jobtype.id;
								if(data.msg[i].jobitem_user.jobitem.jobitem_status == -1) {
									button = "评价";
								}
								if(data.msg[i].jobitem_user.jobitem.jobitem_status == -2) {
									button = "删除";
								}
								if(data.msg[i].jobitem_user.jobitem.job.decoration_type == 1) {
									house = "毛坯";
								} else {
									house = "旧房改造";
								}
								if(data.msg[i].jobitem_user.unit == 1) {
									unit = "平米";
								} else {
									unit = "延米";
								}
								jQuery("#show").append('<div class="mui-card">' +
									'<table border="0" width="100%"><tr><td height="2px" colspan="2"></td></tr><tr><td width="5px"></td><td align="right" class=" mui-badge mui-badge-blue"><h4>' + data.msg[i].jobitem_user.jobitem.jobtype.name + '</h4></td><td ><h3>' + data.msg[i].jobitem_user.jobitem.job.community + '</h3></td><td></td><td class="mui-badge mui-badge-green" id="urgent_fee_' + data.msg[i].jobitem_user.jobitem.id + '" style="display: none;">加急费:' + data.msg[i].jobitem_user.jobitem.urgent_fee + '</td></tr></table>' +
									'<table><tr id="show' + i + '">&nbsp;&nbsp;&nbsp;<td style="margin-left: 20%;">&nbsp;&nbsp;&nbsp;技能:</td></tr></table>' +
									'<table><tr><td align="left" width="70%">&nbsp;&nbsp;&nbsp;面积：' + data.msg[i].jobitem_user.jobitem.area + unit + '</td>' +
									'<td align="right" width="30%" >酬劳：' + data.msg[i].jobitem_user.jobitem.salary + '元</td></tr>' +
									'<tr><td align="left" width="20%" >&nbsp;&nbsp;&nbsp;房屋类型：' + house + '</td></tr></table>' +
									'<table class="mui-pull-right"  style="margin-bottom: 2%;"><tr colspan="2" ><td><input type="submit" value="详情" class="mui-pull-right" onclick="order_info(' + data.msg[i].jobitem_user.jobitem.id + ',' + data.msg[i].jobitem_user.jobitem.job.user.id + ',' + flag + ')"></td>' +
									'<td><input  type="submit" id="submit_' + i + '" value=' + button + ' class="mui-pull-right" onclick="submit_onclick(' + i + ')">&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;</td></tr>' +
									'</table>' +
									'</div>');
								for(z = 0; z < data.msg[i].skills.length; z++) {
									jQuery("#show" + i).append(
										'<td id="p' + data.msg[i].skills[z].id + 'Style" class="mui-pull-left mui-badge mui-badge-green">' + data.msg[i].skills[z].name + '&nbsp;</td>'
									);
									if(data.msg[i].jobitem_user.jobitem.urgent_fee != 0) {
										document.getElementById("urgent_fee_" + data.msg[i].jobitem_user.jobitem.id).setAttribute("style", "display: ;");
									}
								}
							}
							w.close();
						}
						w.close();
					},
					error: function() {
						w.close();
						alert("网络连接出错！");
					}
				});
			});
		})(mui, document);

		//查看工作详细信息
		function order_info(jobitem_id, boss_id, flag) {
			console.log("order_info:发布订单id" + jobitem_id);
			console.log("工长id" + boss_id);
			var baseUrl = 'order_info.html';
			var url = mui.os.plus ? baseUrl : baseUrl + '?jobitem_id=' + jobitem_id + '?boss_id' + boss_id + "?flag" + flag;
			mui.openWindow({
				url: url,
				extras: {
					jobitem_id: jobitem_id,
					boss_id: boss_id,
					flag: flag,
				}

			})
		}

		function submit_onclick(button_id) {
			if($("#submit_" + button_id).val() == "删除") {
				var info = document.getElementById("info");
				var btnArray = ['否', '是'];
				mui.confirm('是否删除订单，确认？', '提示', btnArray, function(e) {
					if(e.index == 1) {
						var w = plus.nativeUI.showWaiting("正在加载...\n");
						delete_order(button_id);
						w.close();
					}
				})

			}
			if($("#submit_" + button_id).val() == "评价") {
				var info = document.getElementById("info");
				var btnArray = ['否', '是'];
				mui.confirm('是否评价，确认？', '提示', btnArray, function(e) {
					if(e.index == 1) {
						var w = plus.nativeUI.showWaiting("正在加载...\n");
						evaluate(button_id);
						w.close();
					}
				})

			}
		}
		//评价页面跳转
		function evaluate(button_id, user_id) {
			var baseUrl = 'evaluate.html';
			var flag = 2;
			var i = button_id;
			var user_id = localStorage.getItem("user_id");
			var url = mui.os.plus ? baseUrl : baseUrl + '?jobitem_user_id=' + jobitem_user_id[i] + '?appraiser_id=' + user_id + '?flag=' + flag + "?appraiseobject_id=" + appraiseobject_id[i] + "?jobtype_id=" + jobtype_id[i];
			mui.openWindow({
				url: url,
				extras: {
					jobtype_id: jobtype_id[i],
					jobitem_user_id: jobitem_user_id[i],
					appraiser_id: user_id,
					appraiseobject_id: appraiseobject_id[i],
					flag: flag,
				}
			})
		}

		function delete_order(button_id) {
			var w = plus.nativeUI.showWaiting("正在加载...\n");
			var i = button_id;
			$.ajax({
				contentType: "application/json",
				type: "get",
				url: url_3 + "end_request.do?jsoncallback=?",
				data: "jobitem_user_id=" + jobitem_user_id[i],
				dataType: "json",
				success: function(data) {
					w.close();
					mui.alert("删除成功！");
					location.reload(); //刷新页面
				},
				error: function(data) {
					w.close();
					alert(data);
					alert("网络连接出错！");
				}
			});
		}
	</script>

</html>